/**
 * Created by lxh on 2018/1/5.
 */
import React, {PureComponent} from 'react';
import moment from 'moment';
import {Link} from 'dva/router';
import {Table, Switch, Icon, Alert, Badge, Button} from 'antd';
import styles from './index.less';
import {powerControl} from '../../utils/powerControl';
const AuthButton = powerControl(Button);

export default class ShopManageTable extends PureComponent {
    handleTableChange = (pagination) => {
        this.props.handleTableChange(pagination);
    }
    handleEdit = (record) => {
        this.props.handleEdit(record);
    }

    render() {
        const {data: {list, pagination}, loading} = this.props;
        console.log("页码",pagination)
        const columns = [
            {
                title: '店铺编码',
                dataIndex: 'id',
            }, {
                title: '店铺名称',
                dataIndex: 'shop_name',
            },
            {
                title: '店铺标题',
                dataIndex: 'shop_title',
            },
            {
                title: '详细地址',
                dataIndex: 'shop_address',
            },
            {
                title: '店铺email',
                dataIndex: 'seller_email',

            },
            {
                title: '客服qq',
                dataIndex: 'kf_qq',
            },
            {
                title: '客服旺旺',
                dataIndex: 'kf_ww',
            }, {
                title: '客服电话',
                dataIndex: 'kf_tel',
            }, {
                title: '店铺logo',
                dataIndex: 'shop_logo',
            }, {
                title: '网站管理员备注信息',
                dataIndex: 'remark'
            }, {
                title: '状态',
                dataIndex: 'status',
                render(val) {
                    console.log(val);
                    return <Switch checkedChildren={<Icon type="check"/>} unCheckedChildren={<Icon type="cross"/>}
                                   defaultChecked={val} />;
                },
            }, {
                title: '操作',
                fixed: 'right',
                width: 230,
                render: (text, record) => (
                    <p>
                        <AuthButton ghost auth="shopManage.edit" className={styles.btn} size="small"
                                    onClick={() => this.handleEdit(record)}>编辑</AuthButton>
                        <span className={styles.splitLine}/>
                        <Link to={{pathname: '/distributorManage/shopAddGoods', state: record.id ,returnPath:'/distributorManage/shopManage'}}>
                            <AuthButton ghost className={styles.btn} size="small"
                                        auth="shopManage.goodsmanager">商品管理</AuthButton>
                        </Link>
                    </p>
                ),
            },
        ];

        const paginationProps = {
            showSizeChanger: true,
            showQuickJumper: true,
            ...pagination,
        };

        return (
            <div className={styles.standardTable}>
                <Table
                    loading={loading}
                    rowKey={record => record.id}
                    dataSource={list}
                    columns={columns}
                    pagination={paginationProps}
                    onChange={(pagination) => this.handleTableChange(pagination)}
                    scroll={{x: 1500}}
                />
            </div>
        );
    }
}

